﻿using System.Web;
using System.Web.SessionState;


//using iSun.CRM.Library;

using iSun.Model;
using iSun.BLL.Base;

namespace iSun.Web.UI.Controls
{
    public class TreeJsonData : JsonData, IHttpHandler, IRequiresSessionState 
    {
        /// <summary>
        /// You will need to configure this handler in the web.config file of your 
        /// web and register it with IIS before being able to use it. For more information
        /// see the following link: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpHandler Members

        public bool IsReusable
        {
            // Return false in case your Managed Handler cannot be reused for another request.
            // Usually this would be false in case you have some state information preserved per request.
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            string _table = GetStringFromQueryString("table", "");
            System.Guid _pid = GetGuidFromQueryString("pid");
            switch (_table)
            {
                case "dept": //部门
                    iSun.BLL.BDeptView bDeptView = new BLL.BDeptView();
                    context.Response.Write(bDeptView.ConvertToDojoJSON(bDeptView.getDeptTreeView(_pid)));
                    break;
                case "SysMenu": //菜单(功能模块)
                    iSun.BLL.BMenuView bMenuView  = new BLL.BMenuView();
                    context.Response.Write(bMenuView.ConvertToDojoJSON(bMenuView.getMenuTreeView(_pid)));
                    break;
                case "post": //岗位
                    break;
                case "":     //
                    break;
                default:     
                    iSun.BLL.BDeptView bDeptView2 = new BLL.BDeptView();
                    context.Response.Write(bDeptView2.ConvertToDojoJSON(bDeptView2.getDeptTreeView(_pid)));
                    break;
            }
        }

        #endregion
    }
}
